#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;

const int N = 26;

int lt[N+1], rt[N+1];

int c2d(char c)
{       
    return c - 'A' + 1;
}           

char d2c(int d)
{       
    return d - 1 + 'A';
}       

int rebuild(int n, int pre[], int in[])
{   
    if (n == 0) return 0;
    int root = pre[0];
    if (n == 1) {
        lt[root] = rt[root] = 0;
        return root;
    }
    int m;
    for (m = 0; m < n; m ++) {
        if (in[m] == root) break;
    }
    lt[root] = rebuild(m, pre+1, in);
    rt[root] = rebuild(n-m-1, pre+m+1, in+m+1);
    return root;
}

void post(int root)
{
    if (root == 0) return;
    post(lt[root]);
    post(rt[root]);
    printf("%c", d2c(root));
}

int main(void)
{
    int n;
    char s1[N+1], s2[N+1];
    int pre[N+1], in[N+1];
    while (scanf("%s%s", s1, s2) != EOF) {
        n = strlen(s1);
        for (int i = 0; i < n; i ++) {
            pre[i] = c2d(s1[i]);
            in[i] = c2d(s2[i]);
        }

        int root = rebuild(n, pre, in);
        post(root);
        printf("\n");
    }

    return 0;
}
